package com.api.test;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.api.client.ApiClient;
import com.api.client.ServiceRequest;
import com.web.imp.AbstractTest;
import com.zyncro.user.User;
import com.zyncro.user.ZyncroUser;
import com.zyncro.util.Service;

public class ApiTestCreateHtmlFeed extends AbstractTest{
	
	private static final String URN_EVENT_PATTERN = "syncrum:event:\\w{8}?-\\w{4}?-\\w{4}?-\\w{4}?-\\w{12}?";
	
	@User(id = "MAIN_ADMIN")
	private ZyncroUser user;
	
	private String html = "<h1>Flashing comment</h1><h2>Yeah</h2>";
	
	private String indexableContent = "indexableContent";
	
//	@Test
	public void testCreateCorporateFeed(){
		
		ApiClient apiClient = ApiClient.forUser(user.getEmail(), user.getPassword());
		
		ServiceRequest request = apiClient.newRequest(Service.CREATE_CORPORATE_FEED);
		
		request.setParameter("comment", "This is the comment");
		request.setParameter("indexableContent", indexableContent);
		request.setParameter("htmlComment", html);
		
		String result = request.send();
		
		Assert.assertTrue(result.matches(URN_EVENT_PATTERN));
	}	
	
//	@Test
	public void testCreatePersonalFeed(){
		
		ApiClient apiClient = ApiClient.forUser(user.getEmail(), user.getPassword());
		
		ServiceRequest request = apiClient.newRequest(Service.CREATE_PERSONAL_FEED);
		
		request.setParameter("comment", "This is the comment");
		request.setParameter("indexableContent", indexableContent);
		request.setParameter("htmlComment", html);
		
		String result = request.send();
		
		Assert.assertTrue(result.matches(URN_EVENT_PATTERN));
	}
	
	@Test
	public void testCreateGroupFeed(){
		
		ApiClient apiClient = ApiClient.forUser(user.getEmail(), user.getPassword());
		
		ServiceRequest request = apiClient.newRequest(Service.CREATE_GROUP_DEPARTMENT_FEED);
		
		request.setParameter("idGroupDepartment", user.getProperty("group.owned.urn"));
		request.setParameter("indexableContent", indexableContent);
		request.setParameter("comment", "This is the comment");
		request.setParameter("htmlComment", html);
		
		String result = request.send();
		
		Assert.assertTrue(result.matches(URN_EVENT_PATTERN));
	}
	
//	@Test
	public void testCreateDepartmentFeed(){
		
		ApiClient apiClient = ApiClient.forUser(user.getEmail(), user.getPassword());
		
		ServiceRequest request = apiClient.newRequest(Service.CREATE_GROUP_DEPARTMENT_FEED);
		
		request.setParameter("idGroupDepartment", user.getProperty("department.owned.urn"));
		request.setParameter("indexableContent", indexableContent);
		request.setParameter("comment", "This is the comment");
		request.setParameter("htmlComment", html);
		
		String result = request.send();
		
		Assert.assertTrue(result.matches(URN_EVENT_PATTERN));
	}
}